const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Food = sequelize.define('Food', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true
  },
  category: {
    type: DataTypes.ENUM('staple', 'meat', 'vegetable', 'fruit', 'drink', 'other'),
    allowNull: false,
    defaultValue: 'other'
  },
  unit: {
    type: DataTypes.STRING,
    allowNull: false,
    defaultValue: '克'
  },
  calories: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  protein: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  fat: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  carbs: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  fiber: {
    type: DataTypes.FLOAT,
    allowNull: true,
    defaultValue: 0
  },
  sugar: {
    type: DataTypes.FLOAT,
    allowNull: true,
    defaultValue: 0
  },
  sodium: {
    type: DataTypes.FLOAT,
    allowNull: true,
    defaultValue: 0
  },
  image: {
    type: DataTypes.STRING,
    allowNull: true
  },
  isCustom: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false
  },
  createdBy: {
    type: DataTypes.INTEGER,
    allowNull: true,
    references: {
      model: 'Users',
      key: 'id'
    }
  }
});

module.exports = Food; 